#!/usr/bin/env python
# -*- coding: utf-8 -*-

# #portugues@ScoutLink 2006 JOTI Bot (slbot)
# Copyright (c) 2006, ScoutLink #portugues team
# This source is released under the New BSD License. See the LICENSE file for further
# information.

# $Author: fmobus $
# $Date: 2006-09-09 21:53:59 -0300 (Sáb, 09 Set 2006) $ 

__version__ = "$Revision: 21 $"
# $Source$

import commands
import sys
import os
import time

class SLLog:
  def __init__(self, outfile, errfile, level = 0):
    self.__si = file('/dev/null','r')
    self.__so = file(outfile,'a+',0)
    self.__se = file(errfile,'a+',0)
    self.__pid = os.getpid()

    # "forget" calling terminal's file descriptors by
    # reassining stdin, stdout and stderr to passed parameters
    os.dup2(self.__si.fileno(), sys.stdin.fileno())
    os.dup2(self.__so.fileno(), sys.stdout.fileno())
    os.dup2(self.__se.fileno(), sys.stderr.fileno())

  def log(self,msg):
    print >>self.__so, "[%s] [%s] %s" % (self.__pid, time.asctime(), msg)

  def error(self,msg):
    print >>self.__se, "[%s] [%s] %s" % (self.__pid, time.asctime(), msg)
